package server

import (
	"context"
	"you-ku-mgr/video-server/basic/config"
	"you-ku-mgr/video-server/basic/handler/model"
	__ "you-ku-mgr/video-server/basic/proto"
)

type Server struct {
	__.UnimplementedVideoServer
}

func (s Server) CreateVideo(_ context.Context, in *__.CreateVideoReq) (*__.CreateVideoResp, error) {
	//TODO implement me
	var video model.Video
	video = model.Video{
		Title:   in.Title,
		Content: in.Content,
		Status:  in.Status,
		Address: in.Address,
		Year:    in.Year,
		Image:   in.Image,
	}
	err := config.DB.Create(&video).Error
	if err != nil {
		return &__.CreateVideoResp{
			Code: 0,
			Msg:  "上传失败",
		}, nil
	}
	return &__.CreateVideoResp{
		Code: 200,
		Msg:  "上传成功",
	}, nil
}

func (s Server) CreateUser(_ context.Context, in *__.CreateUserReq) (*__.CreateUserResp, error) {
	//TODO implement me
	var user model.User
	user = model.User{
		Tel:      in.Tel,
		Password: in.Password,
	}

	err := config.DB.Create(&user).Error
	if err != nil {
		return &__.CreateUserResp{
			Code: 0,
			Msg:  "注册失败",
		}, nil
	}
	return &__.CreateUserResp{
		Code: 200,
		Msg:  "注册失败",
	}, nil
}

func (s Server) mustEmbedUnimplementedVideoServer() {
	//TODO implement me
	panic("implement me")
}
